Skip to content

Added my-issues function#2

Open
SiMiZZZ wants to merge 1 commit intomasterfrom
my-issues
Open

Added my-issues function#2
SiMiZZZ wants to merge 1 commit intomasterfrom
my-issues

Conversation

@SiMiZZZ
Copy link
Owner

@SiMiZZZ SiMiZZZ commented Feb 26, 2026

No description provided.


println!("🔍 Fetching your assigned issues...");
match get_my_issues(&JiraClient::new(&config), project.as_deref(), all).await {
Ok(issues) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok(issues) if issues.is_empty() => {1}
Ok(issues) => {2}

pub async fn get_my_issues(
jira_client: &JiraClient,
project: Option<&str>,
include_done: bool,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В сервис просочился пользовательский флаг. Стоит enum сделать и выбирать его элементы в зависимости от флага пользователя из команды

project: Option<&str>,
include_done: bool,
) -> Result<Vec<Issue>, JiraClientError> {
let mut jql = "assignee = currentUser()".to_string();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

сбор jql если вынести в отдельную функцию (а лучше Trait builder) и даже можно тестами отдельно покрыть.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct JQLBuilder {
    inner: String
}

);

let mut all_issues = Vec::new();
let max_results = 50;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно в const вынести на уровень модуля

jql.push_str(" ORDER BY updated DESC");

let api_url = format!(
"{}/rest/api/2/search",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: можно использовать тип Url и соединять в него пути вместо форматирования строчек.

let search_response: SearchResponse =
response.json().await.map_err(|_| JiraClientError::Parse)?;

let fetched = search_response.issues.len() as i32;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а зачем так много, i16 не хватит? также подходит usize


#[derive(Debug, Clone)]
pub struct JqlBuildError {
pub message: String,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А лучше enum с thiserror, чем разные сообщения, которые не разбиты по кейсам

impl std::error::Error for JqlBuildError {}

/// Project keys must be uppercase alphanumeric + underscore only.
fn validate_project_key(key: &str) -> Result<(), JqlBuildError> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse dont validate. Тут стоит завести тип ProjectKey(String), который парсится из &str, String через FromString, TryFrom (как удобнее)


/// Build the final JQL string.
pub fn build(self) -> String {
let mut jql = String::new();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут мутация строки и ниже цикл foreach. Для раста это малость неоптимально и будет сводить компилятор с ума, так как нет оптимизаций итераторами. Предлагаю использовать коллекцию conditions через iter, каждое значение смаппить в строчку через map(|conj| write!(...)) и после всего этого применить join на результат итератора

let _ = write!(jql, "{} {} {}", cond.field, cond.operator, cond.value);
}

if !self.order_by.is_empty() {
Copy link

@LEVLLN LEVLLN Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вижу, что в два-три этапа собирается jql, но можно все разные части в разных переменных строк собрать. А на выходе соединить все части эти. Сборка разных частей строк спокойно делится на функции приватные и для них можно писать десты в docstring :)

/// Add a condition joined by OR.
#[allow(dead_code)]
pub fn or(mut self, field: Field, op: Operator, value: Value) -> Self {
let conjunction = if self.conditions.is_empty() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.conditions.is_empty().then(|| Some(Conjunction::Or))


/// Right-hand side value in a JQL condition.
#[derive(Debug, Clone)]
#[allow(dead_code)]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а почему dead_code?


/// Add a condition joined by AND (or as the first condition).
pub fn and(mut self, field: Field, op: Operator, value: Value) -> Self {
let conjunction = if self.conditions.is_empty() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.conditions.is_empty().then(|| Some(Conjunction::AND))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants